package com.example.salesystem.mock;

import com.example.salesystem.service.IUserService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;

public class InitMockito3 {
    @Mock
    private IUserService mockUserService;
    @Spy
    private IUserService spyUserService;

    @BeforeEach
    public void init() {
        MockitoAnnotations.openMocks(this);
    }

    @Test
    public void testMock1() {
        // 判断某对象是不是 mock 对象 -- true
        Assertions.assertTrue(Mockito.mockingDetails(mockUserService).isMock());
        // 判断某对象是不是 spy 对象 -- false
        Assertions.assertFalse(Mockito.mockingDetails(mockUserService).isSpy());
        // 判断某对象是不是 mock 对象 -- true -- spy 对象是另一种不同类型的 mock 对象
        Assertions.assertTrue(Mockito.mockingDetails(spyUserService).isMock());
        // 判断某对象是不是 spy 对象 -- true
        Assertions.assertTrue(Mockito.mockingDetails(spyUserService).isSpy());
    }
}

